﻿using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SheepStorage.API.Application.Command.lishun;
using SheepStorage.API.Application.Command.SheepRecordCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Controllers
{
    /// <summary>
    /// 羊只档案查询
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [AllowAnonymous]
    public class SheepRecordController : ControllerBase
    {

        IMediator _mediator;
        ISheepRecordService _res;

        public SheepRecordController(IMediator mediator, ISheepRecordService res)
        {
            _mediator = mediator;
            _res = res;
        }
        /// <summary>
        /// 羊只档案添加(中介)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddSheepRecords(AddSheepRecordCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 羊只档案详细
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<SheepRecord>> ShowSheepRecordDTO(ShowSheepRecordCommand? command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 羊只档案显示查询
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<List<SheepRecordOutput>>> ShowSheepRecord(SheepRecordCommand? command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DelSheepRecord(DelSheepRecordCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 根据栋舍名称查询栋舍id
        /// </summary>
        /// <param name="buildingManagementName"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult MyGetSheepField(string buildingManagementName)
        {
            var list = _res.MyGetSheepField(buildingManagementName);
            return Ok(list);
        }



        /// <summary>
        /// 种母查询
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public IActionResult ShowSheepMom()
        {
            return Ok(_res.ShowSheepMom());
        }
        /// <summary>
        /// 种公查询
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public IActionResult ShowSheepDad()
        {
            return Ok(_res.ShowSheepDad());
        }

        /// <summary>
        /// 批量修改繁殖状态
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> UpdateRecordBreedState(UpdateSheepRecordBreedStateCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 批量修改转入栋舍栏位
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> UpdateNewBuilding(UpdateNewBuildingCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 根据繁殖状态查询羊只档案
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<List<SheepRecord>>> ShowBreedState(ShowBreedStateCommand command)
        {
            return await _mediator.Send(command);
        }


        /// <summary>
        /// 修改羊只档案
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> UpdateSheepRecord(UpdateSheepRecordCommand command)
        {
            return await _mediator.Send(command);
        }


        /// <summary>
        /// 根据耳号查找羊只档案信息
        /// </summary>
        /// <param name="ov"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetD(string ov)
        {
            return Ok(_res.GetDs(ov));
        }

        [HttpGet]
        public IActionResult GetSheepRecordAll()
        {
            return Ok(_res.GetSheepRecordAll());

        }


    }
}
